local skel = fk.CreateSkill {
  name = "emo__jianshi",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__jianshi"] = "监视",
  [":emo__jianshi"] = "锁定技，游戏开始时，你选择一名其他角色，其手牌对你可见，每当你使用牌指定其为目标后，获得其一张牌，额外结算一次。回合开始时，若其体力值不大于体力上限的一半，你对除其外所有其他角色造成一点火焰伤害。",

  ["#emo__jianshi-choose"] = "监视一名其他角色，其手牌对你可见",
  ["@[chara]emo__jianshi"] = "监视",
}

skel:addEffect(fk.GameStart, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and #player.room:getOtherPlayers(player, false) > 0
  end,
  on_cost = function (self, event, target, player, data)
    local tos = player.room:askToChoosePlayers(player, {
      min_num = 1, max_num = 1, targets = player.room:getOtherPlayers(player, false), skill_name = skel.name,
      prompt = "#emo__jianshi-choose", cancelable = false,
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local to = event:getCostData(self).tos[1]
    local room = player.room
    room:setPlayerMark(player, "@[chara]emo__jianshi", to.id)
  end,
})

skel:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and
      data.to and data.to.id == player:getMark("@[chara]emo__jianshi")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.use.additionalEffect = (data.use.additionalEffect or 0) + 1
    if not data.to:isNude() then
      local cid = room:askToChooseCard(player, {
        target = data.to, skill_name = skel.name, flag = "he"
      })
      room:obtainCard(player, cid, false, fk.ReasonPrey, player, skel.name)
    end
  end,
})

skel:addEffect(fk.TurnStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    local mate = player.room:getPlayerById(player:getMark("@[chara]emo__jianshi"))
    if not mate then return false end
    return target == player and player:hasSkill(skel.name) and mate.hp <= (mate.maxHp / 2)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getAlivePlayers(), function (p)
      return p ~= player and p.id ~= player:getMark("@[chara]emo__jianshi")
    end)
    for _, p in ipairs(targets) do
      if not p.dead then
        room:doIndicate(player, {p})
        room:damage { from = player, to = p, damage = 1, skillName = skel.name, damageType = fk.FireDamage }
      end
    end
  end,
})

skel:addEffect("visibility", {
  card_visible = function (self, player, card)
    local owner = Fk:currentRoom():getCardOwner(card.id)
    if owner and owner.id == player:getMark("@[chara]emo__jianshi") then
      return true
    end
  end,
})

return skel
